#define _CRT_SECURE_NO_WARNINGS 1

https://leetcode.cn/problems/invert-binary-tree/


/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {

        if (root == NULL)   return root;

        stack<TreeNode*> st;

        st.push(root);

        while (!st.empty())
        {
            TreeNode* temp = st.top();
            st.pop();

            swap(temp->left, temp->right);

            if (temp->left)    st.push(temp->left);
            if (temp->right)   st.push(temp->right);
        }
        return root;
    }
};